#lang racket


(require "constructors-cache.rkt"
         "math.rkt"
         "point.rkt")


(provide cone.pp
         cylinder.pp
         
         box.center
         box.normal)


(define (cone.pp radius base apex)
  (let* ((direction (p-p apex base))
         (height (sph-r direction)))
    (move base
      (rotate (sph-th direction) uz
        (rotate (sph-fi direction) uy
          (cone radius height))))))

(define (cylinder.pp radius base apex)
  (let* ((direction (p-p apex base))
         (height (sph-r direction)))
    (move base
      (rotate (sph-th direction) uz
        (rotate (sph-fi direction) uy
          (cylinder radius height))))))

(define (box.center width length height (center 'center))
  (cond ((eq? center 'bottom)
         (move (p*n uz (/2 height)) (box width length height)))
        (else
         (box width length height))))

(define (box.normal width length height normal (center 'center))
  (rotate
   (p<\p uz normal)
   (pxp uz normal)
   (box.center width length height center)))